import Vue from 'vue'
import App from './App.vue'
import ElementUI, { MessageBox } from 'element-ui'
// import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import router from '../src/router'
import store from '../src/vuex/store'
import http from 'axios'
import '../api/mock'

Vue.config.productionTip = false

// Vue.use(ElementUI)
Vue.use(ElementUI)

//将axios写进vue的原型中去
Vue.prototype.$http = http
Vue.prototype.$confirm = MessageBox.confirm

// 路由守卫

router.beforeEach((to,from,next)=>{
  store.commit('getToken')
  const token = store.state.user.token
  if(!token && to.name !== 'login'){
    next({name:'login'})
  }else{
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
  created(){
    store.commit('addMenu',router)
  }
}).$mount('#app')
